#pragma once


class Solution
{
public:
    int numDecodings(string& s)
    {
        int dp[100] = { 0 };
        int n = s.size();

        //dp[0]
        int a = s[0] - '0';
        dp[0] = s[0] != '0';
        if (n == 1)return dp[0];

        //dp[1]
        int b = s[1] - '0';
        if (s[0] != '0' && s[1] != '0')++dp[1];
        int c = a * 10 + b;
        if (c >= 10 && c <= 26)++dp[1];

        for (int i = 2; i < n; ++i)
        {
            if (s[i] != '0')dp[i] += dp[i - 1];
            int x = (s[i - 1] - '0') * 10 + s[i] - '0';
            if (x >= 10 && x <= 26)
                dp[i] += dp[i - 2];
        }

        return dp[n - 1];
    }
};